package com.itheima.blog.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.api.client.blog.BlogSearch;
import com.itheima.blog.article.entity.TAlbum;
import com.itheima.blog.article.entity.TBlog;
import com.itheima.blog.article.mapper.MyBlogMapper;
import com.itheima.blog.article.mapper.TAlbumMapper;
import com.itheima.blog.article.service.ITAlbumService;
import com.itheima.blog.article.service.ITBlogService;
import com.itheima.blog.article.service.MyBlogService;
import com.itheima.blog.util.UserContext;
import com.itheima.common.utills.CollUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户boke 服务实现类
 * </p>
 * @author lin
 * @since 2023-07-12
 */
@Service
@AllArgsConstructor
public class MyBlogServiceImpl extends ServiceImpl<MyBlogMapper, TBlog> implements MyBlogService {
    private final ITBlogService itBlogService;
    private final ITAlbumService itAlbumService;
    private final MyBlogMapper myBlogMapper;
    private final BlogSearch blogSearch;
    @Override
    public void updateMyBlog(TBlog tBlog) {
       itBlogService.blogDetail(tBlog.getId());
       this.updateById(tBlog);
    }


    @Override
    public void deleteMyBlog(TBlog tBlog) {
        Long user = UserContext.getUser();
        int i = user.intValue();
        if (i==tBlog.getUserId()){
           removeById(tBlog.getId());
        }
    }
    @Override
    public List<String> findImageById(Long id) {

        List<TAlbum> list = itAlbumService.lambdaQuery().eq(TAlbum::getUserId, id).list();
        return list.stream().map(TAlbum::getUrl).collect(Collectors.toList());
    }

    @Override
    public void onOff(TBlog tBlog) {
        myBlogMapper.updateById(tBlog);
    }
    @Override
    public void shangXia(TBlog tBlog) {
//       blogSearch.updateStatus(tBlog);


    }


}
